package demo_0416.hw;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BankManager bankManager = new BankManager("resource/accounts.txt", "resource/report.txt");

        while (true) {
            System.out.println("--------操作界面---------");
            System.out.println("1-显示账户");
            System.out.println("2-更新账户");
            System.out.println("3-添加账户");
            System.out.println("4-删除账户");
            System.out.println("5-生成报告");
            System.out.println("6-退出");
            System.out.println("请选择操作：");
            int choice = scanner.nextInt();
            scanner.nextLine(); // consume newline

            switch (choice) {
                case 1:
                    bankManager.displayAccounts();
                    break;
                case 2:
                    System.out.println("请输入要更新的账户ID:");
                    int updateId = scanner.nextInt();
                    scanner.nextLine(); // consume newline
                    System.out.println("请输入新的名字:");
                    String newFirstname = scanner.nextLine();
                    System.out.println("请输入新的姓氏:");
                    String newLastname = scanner.nextLine();
                    System.out.println("请输入新的余额:");
                    double newBalance = scanner.nextDouble();
                    bankManager.updateAccount(updateId, newFirstname, newLastname, newBalance);
                    break;
                case 3:
                    System.out.println("请输入新账户的ID:");
                    int newId = scanner.nextInt();
                    scanner.nextLine(); // consume newline
                    System.out.println("请输入新的名字:");
                    String newFName = scanner.nextLine();
                    System.out.println("请输入新的姓氏:");
                    String newLName = scanner.nextLine();
                    System.out.println("请输入新的余额:");
                    double newBal = scanner.nextDouble();
                    bankManager.addAccount(new Account(newId, newFName, newLName, newBal));
                    break;
                case 4:
                    System.out.println("请输入要删除的账户ID:");
                    int deleteId = scanner.nextInt();
                    bankManager.deleteAccount(deleteId);
                    break;
                case 5:
                    bankManager.generateReport();
                    break;
                case 6:
                    System.exit(0);
                default:
                    System.out.println("无效的选择，请重新输入。");
            }
        }
    }
}
